﻿using Microsoft.Xna.Framework;

namespace Ultima.Xna.Graphics.UI.Gumps
{
    public class GumpRadio : GumpCheckbox
    {
        private int _groupId;

        public int GroupId
        {
            get { return _groupId; }
            set { _groupId = value; }
        }

        public override bool Checked
        {
            get 
            {
                return base.Checked; 
            }
            set
            {
                if (value)
                {
                    if (Parent != null)
                    {
                        for (int i = 0; i < Parent.Children.Count; i++)
                        {
                            if (Parent.Children[i] is GumpRadio &&
                                Parent.Children[i] != this && ((GumpRadio)Parent.Children[i]).GroupId == _groupId)
                            {
                                ((GumpRadio)Parent.Children[i]).Checked = false;
                            }
                        }
                    }
                }

                base.Checked = value;
            }
        }

        public GumpRadio(Game game)
            : base(game)
        {
            Clickable = true;
        }

        public override void Draw(GameTime gameTime)
        {
            Manager.Renderer.Render(this);

            base.Draw(gameTime);
        }
    }
}
